package com.kiln.juxingqs.adapter

import android.content.Context
import android.content.Intent
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import client.global.commlib.base.BaseLoadmoreAdapter
import client.global.commlib.base.BindingViewHoder
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.GoodsIndex
import com.kiln.juxingqs.databinding.LayoutZrppitemBinding
import com.kiln.juxingqs.ui.JyDetail2Activity
import com.kiln.juxingqs.ui.ZrDetailActivity


class ZrppAdapter : BaseLoadmoreAdapter<GoodsIndex.Goods> {

    lateinit var goodsIndex: GoodsIndex

    constructor(context: Context) : super(context,
        object : DiffUtil.ItemCallback<GoodsIndex.Goods>() {
            override fun areItemsTheSame(
                oldItem: GoodsIndex.Goods,
                newItem: GoodsIndex.Goods
            ): Boolean {
                return false
            }

            override fun areContentsTheSame(
                oldItem: GoodsIndex.Goods,
                newItem: GoodsIndex.Goods
            ): Boolean {
                return false
            }
        }) {
    }

    override fun createVh(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.layout_zrppitem,
                parent,
                false
            )
        )
    }

    override fun bindVh(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as LayoutZrppitemBinding
        val bean = getItem(position)
        binding.bean = bean
        binding.event = this
//        if (bean.name.equals("振中慈缘+")) {
//            binding.bbb.text = "50.00"
//        } else {
//            binding.bbb.text = "200.00"
//        }

    }

    fun submitData(list: MutableList<GoodsIndex.Goods?>, goodsIndex: GoodsIndex) {
        this.goodsIndex = goodsIndex
        if (list.get(0) != null)
            submitList(list)
    }


    fun itemClick(bean: GoodsIndex.Goods) {
        if (bean.deal_status.equals("1")) {
            context.startActivity(Intent(context, JyDetail2Activity::class.java).apply {
                putExtra("goodsId", "${bean.goods_id}")
            })
        } else
            context.startActivity(Intent(context, ZrDetailActivity::class.java).apply {
                putExtra("goodsId", "${bean.goods_id}")
            })


//        else {
//            toast("请在开拍时间竞拍")
//        }

    }


}